Change in openvpn[release/2.6]: dco-win: Ensure correct OVERLAPPED scope
A message that is not in the archive (sent off-list or not yet received): gerrit.1743592292000.I44a73f06c0672c1d288bf46e9424dc0dc2abe054@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/933?usp=email
to review the following change.
Change subject: dco-win: Ensure correct OVERLAPPED scope
......................................................................
dco-win: Ensure correct OVERLAPPED scope
This is a backport of the master commit
f60a493 ("dco-win: Fix crash when cancelling pending operation")
Although I am unable to reproduce this issue on release branch, the code is clearly wrong and has to be fixed.
The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer().
When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption.
This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime.
---
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/socket.c
M src/openvpn/tun.h
4 files changed, 9 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/933/1
src/openvpn/dco_win.c +5 -4
@@ -156,7 +156,8 @@ }void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info) {
@@ -229,8 +230,8 @@ASSERT (0 ); } -OVERLAPPED ov = {0 }; -if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , &ov)) +CLEAR (*ov); +if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , ov)) {DWORD err =GetLastError ();if (err !=ERROR_IO_PENDING )
@@ -239,7 +240,7 @@ }else { -dco_connect_wait (handle, &ov, timeout, sig_info); +dco_connect_wait (handle, ov, timeout, sig_info); } } }
src/openvpn/dco_win.h +2 -1
@@ -41,7 +41,8 @@ create_dco_handle(const char *devname, struct gc_arena *gc);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info);
src/openvpn/socket.c +1 -1
@@ -2148,7 +2148,7 @@ c->c1.tuntap = tt; } - dco_create_socket(c->c1.tuntap->hand, + dco_create_socket(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock->info.lsa->current_remote, sock->bind_local, sock->info.lsa->bind_local, get_server_poll_remaining_time(sock->server_poll_timeout),
src/openvpn/tun.h +1 -0
@@ -196,6 +196,7 @@#ifdef _WIN32HANDLE hand; +OVERLAPPED dco_new_peer_ov;/* used for async NEW_PEER dco call, which might wait for TCP connect */ struct overlapped_io reads;struct overlapped_io writes;struct rw_handle rw_handle;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/933?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054
Gerrit-Change-Number: 933
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/933?usp=email )
Change subject: dco-win: Ensure correct OVERLAPPED scope
......................................................................
Patch Set 1: Code-Review+2
(1 comment)
Patchset:
PS1:
Looks good to me. It looks bigger than the master patch because of the prototype rewrapping, but is doing the same thing. Ubuntu/MinGW also says "it's fine" (did not run, just test compile)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/933?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054
Gerrit-Change-Number: 933
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 02 Apr 2025 11:30:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH 1/1 dco-win: Ensure correct OVERLAPPED scope
In reply to a message not in the archiveFrom: Lev Stipakov <[email protected]...>
This is a backport of the master commit
f60a493 ("dco-win: Fix crash when cancelling pending operation")
Although I am unable to reproduce this issue on release branch, the code is clearly wrong and has to be fixed.
The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer().
When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption.
This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to release/2.6.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/933
This mail reflects revision 1 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/dco_win.c +5 -4
@@ -156,7 +156,8 @@ }void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info) {
@@ -229,8 +230,8 @@ASSERT (0 ); } -OVERLAPPED ov = {0 }; -if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , &ov)) +CLEAR (*ov); +if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , ov)) {DWORD err =GetLastError ();if (err !=ERROR_IO_PENDING )
@@ -239,7 +240,7 @@ }else { -dco_connect_wait (handle, &ov, timeout, sig_info); +dco_connect_wait (handle, ov, timeout, sig_info); } } }
src/openvpn/dco_win.h +2 -1
@@ -41,7 +41,8 @@ create_dco_handle(const char *devname, struct gc_arena *gc);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info);
src/openvpn/socket.c +1 -1
@@ -2148,7 +2148,7 @@ c->c1.tuntap = tt; } - dco_create_socket(c->c1.tuntap->hand, + dco_create_socket(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock->info.lsa->current_remote, sock->bind_local, sock->info.lsa->bind_local, get_server_poll_remaining_time(sock->server_poll_timeout),
src/openvpn/tun.h +1 -0
@@ -196,6 +196,7 @@#ifdef _WIN32HANDLE hand; +OVERLAPPED dco_new_peer_ov;/* used for async NEW_PEER dco call, which might wait for TCP connect */ struct overlapped_io reads;struct overlapped_io writes;struct rw_handle rw_handle;
[Openvpn-devel] [PATCH applied] Re: dco-win: Ensure correct OVERLAPPED scope
I have not tested this beyond "does it make mingw happy" (it does), but stare-at-code and comparison to the master commit (f60a493) makes clear that this is fine.
Your patch has been applied to the release/2.6 branch.
commit 9c888671832041febf9284ca66fb163ab9d54a93
Author: Lev Stipakov Date: Wed Apr 2 13:30:11 2025 +0200
dco-win: Ensure correct OVERLAPPED scope
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31316.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#2) to the change originally created by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/933?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: dco-win: Ensure correct OVERLAPPED scope
......................................................................
dco-win: Ensure correct OVERLAPPED scope
This is a backport of the master commit
f60a493 ("dco-win: Fix crash when cancelling pending operation")
Although I am unable to reproduce this issue on release branch, the code is clearly wrong and has to be fixed.
The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer().
When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption.
This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31316.html
---
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/socket.c
M src/openvpn/tun.h
4 files changed, 9 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/933/2
src/openvpn/dco_win.c +5 -4
@@ -156,7 +156,8 @@ }void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info) {
@@ -229,8 +230,8 @@ASSERT (0 ); } -OVERLAPPED ov = {0 }; -if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , &ov)) +CLEAR (*ov); +if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , ov)) {DWORD err =GetLastError ();if (err !=ERROR_IO_PENDING )
@@ -239,7 +240,7 @@ }else { -dco_connect_wait (handle, &ov, timeout, sig_info); +dco_connect_wait (handle, ov, timeout, sig_info); } } }
src/openvpn/dco_win.h +2 -1
@@ -41,7 +41,8 @@ create_dco_handle(const char *devname, struct gc_arena *gc);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info);
src/openvpn/socket.c +1 -1
@@ -2148,7 +2148,7 @@ c->c1.tuntap = tt; } - dco_create_socket(c->c1.tuntap->hand, + dco_create_socket(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock->info.lsa->current_remote, sock->bind_local, sock->info.lsa->bind_local, get_server_poll_remaining_time(sock->server_poll_timeout),
src/openvpn/tun.h +1 -0
@@ -196,6 +196,7 @@#ifdef _WIN32HANDLE hand; +OVERLAPPED dco_new_peer_ov;/* used for async NEW_PEER dco call, which might wait for TCP connect */ struct overlapped_io reads;struct overlapped_io writes;struct rw_handle rw_handle;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/933?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054
Gerrit-Change-Number: 933
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/933?usp=email )
Change subject: dco-win: Ensure correct OVERLAPPED scope
......................................................................
dco-win: Ensure correct OVERLAPPED scope
This is a backport of the master commit
f60a493 ("dco-win: Fix crash when cancelling pending operation")
Although I am unable to reproduce this issue on release branch, the code is clearly wrong and has to be fixed.
The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer().
When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption.
This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31316.html
---
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/socket.c
M src/openvpn/tun.h
4 files changed, 9 insertions(+), 6 deletions(-)
src/openvpn/dco_win.c +5 -4
@@ -156,7 +156,8 @@ }void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info) {
@@ -229,8 +230,8 @@ASSERT (0 ); } -OVERLAPPED ov = {0 }; -if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , &ov)) +CLEAR (*ov); +if (!DeviceIoControl (handle,OVPN_IOCTL_NEW_PEER , &peer,sizeof (peer),NULL ,0 ,NULL , ov)) {DWORD err =GetLastError ();if (err !=ERROR_IO_PENDING )
@@ -239,7 +240,7 @@ }else { -dco_connect_wait (handle, &ov, timeout, sig_info); +dco_connect_wait (handle, ov, timeout, sig_info); } } }
src/openvpn/dco_win.h +2 -1
@@ -41,7 +41,8 @@ create_dco_handle(const char *devname, struct gc_arena *gc);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, +dco_create_socket (HANDLE handle,OVERLAPPED *ov, +struct addrinfo *remoteaddr,bool bind_local,struct addrinfo *bind,int timeout,struct signal_info *sig_info);
src/openvpn/socket.c +1 -1
@@ -2148,7 +2148,7 @@ c->c1.tuntap = tt; } - dco_create_socket(c->c1.tuntap->hand, + dco_create_socket(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock->info.lsa->current_remote, sock->bind_local, sock->info.lsa->bind_local, get_server_poll_remaining_time(sock->server_poll_timeout),
src/openvpn/tun.h +1 -0
@@ -196,6 +196,7 @@#ifdef _WIN32HANDLE hand; +OVERLAPPED dco_new_peer_ov;/* used for async NEW_PEER dco call, which might wait for TCP connect */ struct overlapped_io reads;struct overlapped_io writes;struct rw_handle rw_handle;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/933?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054
Gerrit-Change-Number: 933
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged